/**
 *     This file is part of cesm-ws.
 *
 *     cesm-ws, Web Service for Community Earth System Model
 *
 *     Copyright (c) 2010, Purdue University and/or affilicates or thrid-party contributors as
 *     indicated by the @author tags or express copyright attribution statements
 *     applied by the authors. All third-party contributions are distributed under
 *     license by Purdue University.
 *
 *     cesm-ws is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with this distribution.  If not, see <http://www.gnu.org/licenses/>.
 */

package edu.purdue.rcac.grid.submit.globus;


/**
 * RSL Attributes enum class
 * 
 * @author Han Zhang
 * 
 */
public enum RSLAttribute {
	RSL_SUBSTITUTION("rsl_substitution"),
	/* GLOBUS attributes */
	ARGUMENTS("arguments"), COUNT("count"), DIRECTORY("directory"), EXECUTABLE(
			"executable"), ENVIRONMENT("environment"), JOB_TYPE("jobType"), MAX_TIME(
			"maxTime"), MAX_WALL_TIME("maxWallTime"), MAX_CPU_TIME("maxCpuTime"), GRAM_MY_JOB(
			"gramMyjob"), STDIN("stdin"), STDOUT("stdout"), STDERR("stderr"), QUEUE(
			"queue"), PROJECT("project"), DRY_RUN("dryRun"), MAX_MEMORY(
			"maxMemory"), MIN_MEMORY("minMemory"), HOST_COUNT("hostCount"),
	/* DUROC attributes */
	LABEL("label"), RESOURCE_MANAGER_CONTACT("resourceManagerContact"), SUBJOB_COMMS_TYPE(
			"subjobCommsType"), SUBJOB_START_TYPE("subjobStartType");

	public String name;

	RSLAttribute(String name) {
		this.name = name;
	}

	public String toString() {
		return this.name;
	}

	public static RSLAttribute fromCamelWord(String CamelWord) {
		return RSLAttribute.valueOf(underscoreUpperCase(CamelWord));
	}

	public static RSLAttribute fromUnderscore(String underscore_word) {
		return RSLAttribute.valueOf(underscore_word.toUpperCase());
	}

	public static String underscoreUpperCase(String CamelWord) {
		String tmp = CamelWord.replaceAll("([A-Z]+)([A-Z][a-z])", "$1_$2");
		return tmp.replaceAll("([a-z0-9])([A-Z])", "$1_$2").replace('-', '_')
				.toUpperCase();
	}
}
